<template>
	<view>
		<my-goods :goodslist="goodslist"></my-goods>
	</view>
</template>

<script>
	export default {
    onLoad(options) {
      if(options.goods_id){
        this.queryobj.cat_id=options.goods_id
      }
      if(options.query){
        this.queryobj.query=options.query
      }
      this.getGoods()
    },
		data() {
			return {
        // 页数索引
        pagenum:1,
				// 搜索商品列表
        goodslist:[],
        queryobj:{
          pagenum:this.pagenum,
          pagesize:5,
          query:'',
          cat_id:''
        },
        total:0,
        isloading:false
			};
		},
    methods:{
      // 发起商品列表请求
      async getGoods(k){
        if(this.isloading) return
        this.isloading=true
        uni.showLoading({
          title:"加载中..."
        })
        const{data:res} = await uni.$http.get(
          '/api/public/v1/goods/search',this.queryobj
          )
        if(res.meta.status!==200) return uni.$showMsg()
        this.goodslist=[...this.goodslist,...res.message.goods]
        this.total=res.message.total
        console.log('这是goodslist',this.goodslist)
        uni.hideLoading({
          complete:()=>{
            uni.stopPullDownRefresh()
            this.isloading=false
          }
        })
      }
    },
    onPullDownRefresh(){
      this.goodslist=[]
      this.getGoods()
    },
    onReachBottom(){
      if(this.pagenum*5>=this.total) return uni.$showMsg()
      this.pagenum=this.pagenum+1
      this.getGoods()
    }
	}
</script>

<style lang="scss">

</style>
